#include "GameWorld.h"

void GameWorld::draw(Viewport *viewport)
{
	float x1, x2, y1, y2;
	Rectangle2 rect;

	this->currentEntity = this->entities.begin();
	while (this->currentEntity != this->entities.end())
	{
		rect.x = currentEntity->get()->getX();
		rect.y = currentEntity->get()->getY();
		rect.width = currentEntity->get()->getTexWidth();
		rect.height = currentEntity->get()->getTexHeight();

		if (viewport->isRectInViewport(rect))
		{
			this->currentEntity->get()->draw(viewport);
		}

		this->currentEntity++;
	}
}

void GameWorld::addRandomHumanDummy(float x, float y)
{
	EntityLiving *dummy = new EntityLiving("res/player.png", "DummyDude");

	dummy->setPosition(x, y);

	GameWorld::entities.push_back(std::make_shared<EntityLiving>(*dummy));
}
void GameWorld::addRandomHumanDummy(Vector2 pos)
{
	EntityLiving *dummy = new EntityLiving("res/player.png", "DummyDude", 40, 114);

	dummy->setPosition(pos.x, pos.y);

	GameWorld::entities.push_back(std::make_shared<EntityLiving>(*dummy));
}

GameWorld::GameWorld(int viewportWidth, int viewportHeight)
{
	sizeX = 1000;
	sizeY = 1000;

	/*
	// Init world
	for (int x = 0; x < sizeX; x++)
	{
		for (int y = 0; y < sizeY; y++)
		{
			tiles[x][y] = new Tile();
		}
	}
	*/
}

GameWorld::~GameWorld(void)
{

}
